<template>
<view>
<view class="container">
  <view class="user_top_block" :style="'height:'+(componentState&&!loginUser.platformUser.managerMendianId?'300rpx':'460rpx')">
      <!--  :style="'height:'+(loginUser.platformUser.managerMendianId?'460rpx':'300rpx')" -->
      <view class="user_top_block_zindex">
          <view class="user_info">
              <view class="user_info_left">
                  <view class="user_info_head" v-if="loginUser&&loginUser.platformUser" :style="'border:8rpx solid '+setting.platformSetting.secondColor" @tap='loginOut'>
                      <image class="user_info_head_img" v-if="loginUser.platformUser.headimgurl" :src='loginUser.platformUser.headimgurl'></image>
                      <image class="user_info_head_img" v-else src='https://image1.sansancloud.com/jianzhan/2017_09/24/16/08/58_464.jpg'></image>
                  </view>
                  <view class="user_info_head" v-else :style="'border:8rpx solid '+setting.platformSetting.secondColor" data-link="login.html?url=aikucun_userinfo.html" @tap="tolinkUrl">
                      <image class="user_info_head_img" src='https://image1.sansancloud.com/jianzhan/2017_09/24/16/08/58_464.jpg'></image>
                  </view>
                  <view class="user_base_info">
                      <text class="use_baser_name" data-link="pre_change_user_info.html" @tap="tolinkUrl" v-if="loginUser&&loginUser.platformUser">{{loginUser.platformUser.nickname||loginUser.platformUser.bindTelno}}</text>
                      <text class="user_base_name" v-else  data-link="login.html?url=aikucun_userinfo.html" @tap="tolinkUrl">登录/注册</text>
                      <view class="fx_tuijian" v-if="loginUser&&loginUser.platformUser&&loginUser.platformUser.parentName">
                          <text class="tui">推</text>
                          <text class="fx_tuijian_telno_img" v-if="loginUser.platformUser.parentTelno" :data-phonenumber="loginUser.platformUser.parentTelno" @tap="calling">联系他</text>
                          <text style="font-size: 24rpx;margin-left: 10rpx;">{{loginUser.platformUser.parentName}}</text>
                      </view>
                      <view style="display: flex;">
                          <!-- setting.platformSetting.secondColor -->
                          <view class="user_parentPlatformUser" :style="'background:rgba(255,255,255,0.4)'" :data-link="myMembers?'level_detail.html?id='+myMembers.id:''" @tap='tolinkUrl'>
                            <image class="fx_recommend_icon" v-if="myMembers" src="https://image1.sansancloud.com/zhihuishangwu/2019_11/15/22/51/10_91.jpg?x-oss-process=style/preview_120"></image>
                            <text :style="'color:' + (myMembers?'#FFD854':'#fff')">{{loginUser.platformUser.userLevelName||'普通用户'}}</text>
                          </view> 
                      </view>
                  </view>
              </view>
          </view>
          <view class="mendian_info_block" v-if="loginUser.platformUser.managerMendianId" >
              <view class="mendian_info_item">
                <text class="mendian_info_title">上月门店销售额(元)</text>
                <text class="mendian_info_value">￥{{mendianTongjiData.perData.monthAmount||0}}</text>
              </view>
              <view class="interval_line"></view>
              <view class="mendian_info_item">
                 <text class="mendian_info_title">本月门店销售额(元)</text>
                <text class="mendian_info_value">￥{{mendianTongjiData.curData.monthAmount||0}}</text>
              </view>
          </view>
      </view>
      <block v-if="loginUser&&loginUser.platformUser.userLevel>0">
          <view class="fx_recommend_btn_bg"></view>
          <view class="fx_recommend_btn" @tap="showPoster">
            <image class="fx_recommend_icon" src="https://image1.sansancloud.com/xianhua/2019_11/15/19/1/47_890.jpg?x-oss-process=style/preview_120"></image>
            <text class="fx_recommend_text">推广分享</text>
          </view>
      </block>
      <!--  #ifdef MP -->
      <view class='fx_recommend_btn_bg ewm' v-if="loginUser"></view>
      <view class='fx_recommend_btn ewm' @tap='clickWxGz' v-if="loginUser&&loginUser.platformUser&&!loginUser.platformUser.openid" >
        <image class='fx_recommend_icon' src='https://image1.sansancloud.com/zhihuishangwu/2019_11/21/16/20/28_464.jpg?x-oss-process=style/preview_120'></image>
        <text class='fx_recommend_text'>绑公众号</text>
      </view>
      <view class='fx_recommend_btn ewm' @tap='clickWxGz' v-if="loginUser&&loginUser.platformUser&&loginUser.platformUser.openid">
        <image class='fx_recommend_icon' src='https://image1.sansancloud.com/zhihuishangwu/2019_11/21/16/22/22_495.jpg?x-oss-process=style/preview_120'></image>
        <text class='fx_recommend_text'>解公众号</text>
      </view>
      <!--  #endif -->
      <!-- 'height:'+(loginUser.platformUser.managerMendianId?'460rpx':'300rpx')+ -->
      <view class="user_info_bg" :style="'height:'+(componentState&&!loginUser.platformUser.managerMendianId?'300rpx':'460rpx')+';background:'+(setting.platformSetting.defaultColor||'#eee')"></view>
      <!-- <block v-if="!componentState">
          	<view class="order_block" :style="'bottom: '+(loginUser.platformUser.managerMendianId?'-216rpx':'-80rpx')">
                <view class="order_top_title" data-link='order_list_0.html?easyStatusName=全部订单&easyStatus=0&needLogin=1'  @tap='tolinkUrl'>
                    <text class="order_top_title_text">所有订单</text>
                    <text>全部</text>
                </view>
                <view class="order_type_list">
                    <view class="order_type_item" v-for="(cells,index) in orderData.cells" :key="index" :data-link='cells.linkUrl' @tap='tolinkUrl'>
                        <view class='order_type_icon_block' :style="'background:'+setting.platformSetting.defaultColor">
                          <view class='red_poient_num' v-if='cells.showCountNum > 0'>{{cells.showCountNum}}</view>
                          <image class="order_type_img" :src="cells.iconPath+'?imageMogr2/thumbnail/400x/interlace/0'"></image>
                        </view>
                        <text class="order_type_name">{{cells.text}}</text>
                    </view>
                </view>
            </view>
      </block> -->
  </view>
  <block v-if="!componentState">
        <view class="order_block" :style="'top: '+(loginUser.platformUser.managerMendianId?'360rpx':'216rpx')">
            <view class="order_top_title" data-link='order_list_0.html?easyStatusName=全部订单&easyStatus=0&needLogin=1'  @tap='tolinkUrl'>
                <text class="order_top_title_text">所有订单</text>
                <text>全部</text>
            </view>
            <view class="order_type_list">
                <view class="order_type_item" v-for="(cells,index) in orderData.cells" :key="index" :data-link='cells.linkUrl' @tap='tolinkUrl'>
                    <view class='order_type_icon_block' :style="'background:'+setting.platformSetting.defaultColor">
                      <view class='red_poient_num' v-if='cells.showCountNum > 0'>{{cells.showCountNum}}</view>
                      <image class="order_type_img" :src="cells.iconPath+'?imageMogr2/thumbnail/400x/interlace/0'"></image>
                    </view>
                    <text class="order_type_name">{{cells.text}}</text>
                </view>
            </view>
        </view>
      <view class="order_block_height" :style="'height: '+(loginUser.platformUser.managerMendianId?'216rpx':'80rpx')"></view>
      <view class="order_other_block">
          <view class="order_other_item" v-for="(cells,indexTwo) in ListData.cells" :key="indexTwo" :data-link='cells.linkUrl' @tap='tolinkUrl'>
              <image class="order_other_item_icon" mode="aspectFit" :src="cells.iconPath+'?imageMogr2/thumbnail/120x/interlace/0'"></image>
              <text class="order_other_item_name">{{cells.text}}</text>
          </view>
      </view>
        <!-- 分销中心 -->
      <view class="fx_block" v-if="setting&&setting.platformSetting.fxLevel" data-link="fx_center.html" @tap="tolinkUrl">
        <view class="fx_left">
            <image class="fx_left_icon" src="https://image1.sansancloud.com/xianhua/2020_4/26/11/30/27_567.jpg?x-oss-process=style/preview_120"></image>
            <text>我的分销中心</text>
        </view>
        <image class="fx_right_icon" src="https://image1.sansancloud.com/xianhua/2020_1/2/18/38/31_120.jpg?x-oss-process=style/preview_120"></image>
      </view>
      <view class="belong_mendian_block" v-if="belongMendianDetail">
          <view class="belong_mendian_left">
              <image class="belong_mendian_banner" :src="belongMendianDetail.logo"></image>
              <view class="belong_mendian_base_info">
                  <text class="belong_mendian_name">{{belongMendianDetail.name}}</text>
                  <view class="belong_mendian_info_item">
                      <image class="belong_mendian_info_icon" mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/41/57_180.jpg?x-oss-process=style/preview_120"></image>
                      <text class="belong_mendian_info_text">{{belongMendianDetail.openTime}}:00-{{belongMendianDetail.closeTime}}:00</text>
                  </view>
                  <view class="belong_mendian_info_item">
                      <image class="belong_mendian_info_icon" mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/41/57_164.jpg?x-oss-process=style/preview_120"></image>
                      <text class="belong_mendian_info_text">{{belongMendianDetail.address}}</text>
                  </view>
              </view>
          </view>
          <view class="belong_mendian_right">
              <view class="belong_mendian_change_block" @click="toNearbyStores">
                  <text class="belong_mendian_change_text">变更提货点</text>
                  <image class="belong_mendian_change_icon" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/41/57_119.jpg?x-oss-process=style/preview_120"></image>
              </view>
              <view class="belong_mendian_btn_block">
                  <view class="belong_mendian_btn_item" @click="navigationToMap(belongMendianDetail)">
                      <image class="belong_mendian_btn_icon" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/41/57_147.jpg?x-oss-process=style/preview_120"></image>
                      <text class="belong_mendian_btn_text">导航</text>
                  </view>
                  <view class="interval_line" style="background: #eee;"></view>
                  <view class="belong_mendian_btn_item" @click="calling(belongMendianDetail.telno)">
                      <image class="belong_mendian_btn_icon" src="https://image1.sansancloud.com/xianhua/2020_3/27/11/41/57_131.jpg?x-oss-process=style/preview_120"></image>
                      <text class="belong_mendian_btn_text">电话</text>
                  </view>
              </view>
          </view>
      </view>
  </block>
  <!-- 订单菜单-栏目 -->
  <block v-else>
   
  </block> 
   <custom-page-index-component id="container" :receiveData="sendCustomPageData" v-if="sendCustomPageData" @refreshFun="getRefreshFun"></custom-page-index-component>
   <footer-component v-if="setting.platformSetting.jishuzhichi"></footer-component> 
   <posters-user-info-component :ewmImgUrl="ewmImgUrl" v-if="posterState" @closePoaster="getChilrenPoster"></posters-user-info-component>
</view>
<!-- 授权窗口 -->
<view v-if="showPopup">
<!-- authorizationCount==1&& -->
<view class="authorizationBg"></view>
<view class="authorization">
  <view class="authorizationPopup">
    <view class="tipContent">
      <text style="font-size:38rpx;">前往微信授权</text>
    </view>
    <view class="buttonArray">
      <button class="button cancel" @tap="cancel">取消</button>
      <button class="button confirm" open-type="getUserInfo" :style="'color:' + setting.platformSetting.defaultColor" @getuserinfo="bindGetUserInfo">确定</button>
    </view>
  </view>
</view>
</view>
</view>
</template>

<script>

export default {
  data() {
    return {
      setting: null,
      userData: null,
      PaiXuPartials: null,
      loginUser: null,
      componentState: false,
	  sendCustomPageData:null,
      //组件的data
      curPersonnelType: -1,
      havaMoreSelectType: [],
      havaMoreSelectTypeArr: [],
      // headData:null,
      myMembers:null,
      showPopup: false,
      blankData: {
        color: "rgb(244,244,244)",
        height: 12
      },
      orderData: {
        cells: [{
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/26/17/53/49_216.jpg",
          linkUrl: "order_list_2.html?easyStatus=2&easyStatusName=待付款&needLogin=1",
          text: "待付款",
          color: "#777777",
          showCountNum: 0
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/26/17/53/49_245.jpg",
          linkUrl: "order_list_3.html?easyStatus=3&easyStatusName=待发货&needLogin=1",
          text: "待发货",
          color: "#777777",
          showCountNum: 0
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/26/17/53/49_251.jpg",
          linkUrl: "order_list_4.html?easyStatus=4&easyStatusName=待收货&needLogin=1",
          text: "待收货",
          color: "#777777",
          showCountNum: 0
        },  
        // {
        //   iconPath: "https://image1.sansancloud.com/xianhua/2020_3/26/17/53/49_264.jpg",
        //   linkUrl: "order_list_4.html?easyStatus=5&easyStatusName=待评价&needLogin=1",
        //   text: "待评价",
        //   color: "#777777",
        //   showCountNum: 0
        // },
        {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/26/17/53/49_279.jpg",
          linkUrl: "back_item_list.html?needLogin=1",
          text: "售后",
          color: "#777777"
        }],
        column: 4,
      },
      ListData: {
        cells: [{
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/6/34_486.jpg",
          linkUrl: "order_pintuan.html?needLogin=1&payStatus=1&orderType=12",
          text: "我的拼单",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/33/15_440.jpg",
          linkUrl: "user_jifen_events.html?needLogin=1",
          text: "我的积分",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/27/27_734.jpg",
          linkUrl: "my_coupons.html?needLogin=1",
          text: "优惠券",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/6/34_506.jpg",
          linkUrl: "my_card_voucher.html?needLogin=1",
          text: "我的卡券",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/27/27_726.jpg",
          linkUrl: "verification_record.html?needLogin=1",
          text: "核销记录",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/6/35_442.jpg",
          linkUrl: "address.html?needLogin=1",
          text: "收货地址",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/6/34_528.jpg",
          linkUrl: "yijian_fankui.html?needLogin=1",
          text: "意见反馈",
          color: "#777777"
        }, {
          iconPath: "https://image1.sansancloud.com/xianhua/2020_3/27/11/6/35_437.jpg",
          linkUrl: "custom_page_about_us?pageNage=关于我们&needLogin=1",
          text: "关于我们",
          color: "#777777"
        }],
        column: 3,
        showType: 0
      },
      serverData: {
        iconPath: "https://image1.sansancloud.com/jianzhan/2018_9/5/19/17/45_862.jpg?x-oss-process=style/preview_120",
        linkUrl: "mendian_center.html?needLogin=1",
        text: "我是服务商",
        color: "#777777"
      },
      servantData: {
        iconPath: "https://image1.sansancloud.com/jianzhan/2018_9/5/19/17/45_862.jpg?x-oss-process=style/preview_120",
        linkUrl: "servant_center.html?needLogin=1",
        text: "我是服务人员",
        color: "#777777"
      },
	  moreSelectType:[
		{
		  iconPath: "https://image1.sansancloud.com/jianzhan/2018_9/5/19/17/45_862.jpg?x-oss-process=style/preview_120",
		  linkUrl: "mendian_center.html?needLogin=1",
		  text: "我是服务商",
		  typeText: 'mendian',
		  color: "#777777",
		  ownState: false,
		},{
		  iconPath: "https://image1.sansancloud.com/jianzhan/2018_9/5/19/17/45_862.jpg?x-oss-process=style/preview_120",
		  linkUrl: "servant_center.html?needLogin=1",
		  text: "我是服务人员",
		  typeText:'servant',
		  color: "#777777",
		  ownState: false,
		}, {
		  iconPath: "https://image1.sansancloud.com/jianzhan/2018_9/5/19/17/45_862.jpg?x-oss-process=style/preview_120",
		  linkUrl: "servant_target_center.html?needLogin=1",
		  text: "我是服务对象",
		  typeText: 'servantTarget',
		  color: "#777777",
		  ownState: false,
		}
	  ],
      posterState: false,
      ewmImgUrl: "",
      userInfo: "",
      openShow:false,
      belongMendianDetail:null,
      mendianTongjiData:{},
      fxDetail:null,
    };
  },

  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let loginUser=getApp().globalData.loginUser||null;
    console.log("getApp().globalData.loginUser",loginUser)
    if (loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that);
    }
	
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  onShow: function () {
      let that=this;
      getApp().globalData.addAuthorizationListenerItem(that)
      // that.getSessionUserInfo();
      that.setData({
        setting: getApp().globalData.setting,
        properties: getApp().globalData.properties
      });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.getSessionUserInfo();
    // this.getParac();
    // console.log(this.setting);
    let that=this;
    that.getSessionUserInfo();
    if (getApp().globalData.loginUser) {
      that.checkState();
    } else {
      getApp().globalData.addLoginListener(that); 
      // getApp().globalData.showToastLoading('loading', true);
      // that.setTimeoutLogin(that.conut);
    }
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */

  /* 分享 */
  onShareAppMessage: function () {
    return getApp().globalData.shareForFx2(getApp().globalData.miniIndexPage);
  },
  methods: {
    // 跳转（附近门店跳到下一个页面）
    toNearbyStores: function (e) {
      var that = this;
      wx.navigateTo({
        url: '../../pages/nearby_stores/index',
        success: function () {
          getApp().globalData.currentMendianComponentCallback = that.callback;
          getApp().globalData.currentMendianComponent = that;
        }
      })
    },
    // 返回的信息
    callback: function (mendianBean) {
      console.log("===call back====", mendianBean)
      getApp().globalData.currentMendianComponent.setData({
        belongMendianDetail: mendianBean,
      })
    },
    calling:function(telno){
        getApp().globalData.calling(telno)
    },
    navigationToMap:function(info){
        getApp().globalData.navigationToMap(info)
    },
    getRefreshFun:function(){
        let that=this;
        that.getSessionUserInfo();
        if (getApp().globalData.loginUser) {
          that.checkState();
        } else {
          getApp().globalData.addLoginListener(that); 
          // getApp().globalData.showToastLoading('loading', true);
          // that.setTimeoutLogin(that.conut);
        }
    },
    /* 获取数据 */
    getMembersListData: function (loginUser) {
      let that = this;
      let customIndex = getApp().globalData.AddClientUrl("/wx_find_user_levels.html");
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log('====getUserCardPackage-res===', res);
          if (res.data.errcode == 0) {
            let data = res.data.relateObj;
            if(data.length!=0){
                for (let i = 0; i < data.length; i++) {
                  if (loginUser && data[i].levelValue == loginUser.platformUser.userLevel) {
                    console.log("拥有会员",data[i]);
                    that.setData({
                      myMembers: data[i]
                    });
                  }
                }
            }
          } else {
            wx.showModal({
              title: '提示',
              content: '主人~请求超时！确认重新加载',
              success: function (res) {
                if (res.confirm) {
                  that.getUserCardPackage();
                } else if (res.cancel) {
                  console.log('用户点击取消');
                }
              }
            });
          }
        },
        complete: function (res) {}
      });
    },
    //获取推广中心，查看是否有资格
    get_fx_detailFun: function (setting) {
      console.log('-------推广中心--------');
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_fx_data.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===get_fx_detail===", res);
          if (res.data.errcode == '0') {
            let fxDetail = res.data.relateObj;
            that.setData({
              fxDetail: fxDetail
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    // 关闭海报
    getChilrenPoster(e) {
      let that = this;
      that.setData({
        posterState: false
      });
    },

    clickWxGz: function () {
      let that = this;
      console.log('===bindWxGz====', that.loginUser);
      let loginUser = that.loginUser;
      let title = "你确定要绑定公众号推送嘛~";

      if (loginUser.platformUser.openid) {
        title = "你确定要解绑公众号推送嘛~";
      }

      wx.showModal({
        title: '提示',
        content: title,
        success: function (res) {
          if (res.confirm) {
            if (!loginUser.platformUser.openid) {
              that.bindWxGz();
            } else {
              that.unBindWxGz();
            }
          } else if (res.cancel) {}
        }
      });
    },
    bindWxGz: function () {
      let that = this;
      let paramsUrl = "https://mini.sansancloud.com/chainalliance/" + getApp().globalData.clientNo + "/bindWxGz.html?platformUserId=" + that.loginUser.platformUser.id;
      that.tolinkUrl(paramsUrl);
      that.getSessionUserInfo();
    },
    unBindWxGz: function () {
      let that = this;
      let customIndex = getApp().globalData.AddClientUrl("/wx_unbind_wx_gz_openid.html"); //拿custom_page

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("====== res.data=========", res.data);
          wx.hideLoading();

          if (!res.data.errcode || res.data.errcode == '0') {
            wx.showToast({
              title: '解绑成功~',
              icon: 'success',
              duration: 1000
            });
            that.getSessionUserInfo();
          } else {
            console.log('加载失败');
            wx.showToast({
              title: res.data.errMsg + '~',
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
          }
        },
        fail: function (res) {
          console.log(res);
          wx.hideLoading();
        }
      });
    },
    showPoster: function () {
      let that = this;
      console.log('===showPoster====', that.loginUser.id);

      if (that.loginUser && that.loginUser.platformUser.id) {
        let ewmImgUrl = getApp().globalData.getQrCode({
          type: "user_info",
          id: that.loginUser.platformUser.id
        });
        that.setData({
          posterState: true,
          ewmImgUrl: ewmImgUrl
        });
      } else {
        wx.showModal({
          title: '提示',
          content: '您还未登录，点击【确定】重新加载',
          success: function (res) {
            if (res.confirm) {
              that.getSessionUserInfo();
              this.getParac();
            } else if (res.cancel) {}
          }
        });
      }
    },
    getParac: function () {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/custom_page_userinfo.html", {}, 'get', '1'); //拿custom_page

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("====== res.data=========", res.data);
          wx.hideLoading();

          if (!res.data.errcode || res.data.errcode == '0') {
            that.setData({
              componentState: true
            });
          } else {
            console.log('加载失败');
            that.setData({
              componentState: false
            });
          }
        },
        fail: function (res) {
          console.log(res);
          wx.hideLoading();
          wx.showModal({
            title: '提示',
            content: '加载失败，点击【确定】重新加载',
            success: function (res) {
              if (res.confirm) {
                that.getParac();
              } else if (res.cancel) {
                getApp().globalData.toIndex();
              }
            }
          });
        }
      });
    },
    loginOut: function () {
      // wx.navigateTo({
      //   url: '/pages/pre_change_user_info/index'
      // });
        wx.chooseMessageFile({
          count: 10,
          type: 'all',
          success :function(res) {
            console.log("==chooseMessageFile===",res)
            const tempFilePaths = res.tempFiles[0]
            let filesParam={};
            let index=tempFilePaths.path.lastIndexOf(".");
            let indexTwo=tempFilePaths.name.lastIndexOf(".");
            filesParam.fileUrl = tempFilePaths.path; 
            filesParam.fileType = tempFilePaths.type;
            filesParam.fileName = tempFilePaths.name.slice(0,indexTwo);
            filesParam.fileSuffix = tempFilePaths.path.slice(index,tempFilePaths.path.length);
            if(filesParam.fileType=='file'){
                 if(filesParam.fileUrl.indexOf('mp3')!=-1){
                     filesParam.fileType='audio'
                 }
            }
            console.log("==filesParam===",filesParam)
            var customIndex = getApp().globalData.AddClientUrl("/file_uploading_two.html", filesParam, 'get');
            console.log("customIndex",customIndex);
            var uploadTask = wx.uploadFile({
              url: customIndex.url,
              filePath: tempFilePaths.path,
              name: 'file',
              header:getApp().globalData.headerPost,
              // formData: customIndex.params,
              success: function (res) {
                var data = JSON.parse(res.data);
                console.log(data);
              },
              fail: function (res) {
                console.log(res);
              }
            });
            uploadTask.onProgressUpdate((res) => {
                console.log('上传进度', res.progress) 
                console.log('已经上传的数据长度', res.totalBytesSent) 
                console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend) 
             })
          }
        })
      
    },
    login: function () {
      this.tolinkUrl("login.html")
    },
    bindPickerChange: function (e) {
      let that = this;
      console.log("====bindPickerChange====", e);
      let index = e.detail.value;
      that.setData({
        curPersonnelType: index
      });
    },
    dellSData: function () {
		let that=this;
		let sendCustomPageData = JSON.stringify({
		  title: 'noTitle',
		  url: "userinfo"
		});
		that.setData({
		  sendCustomPageData: sendCustomPageData
		});
      this.setData({
        // headData: this.headData,
        blankData: this.blankData,
        orderData: this.orderData,
        ListData: this.ListData,
        serverData: this.serverData,
        servantData: this.servantData
      });
    },
    getSessionUserInfo: function () {
      var that = this;
      var postParamUserBank = getApp().globalData.AddClientUrl("/get_session_userinfo.html");
      wx.request({
        url: postParamUserBank.url,
        data: postParamUserBank.params,
        header: getApp().globalData.headerPost,
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            let UserInfo = res.data.relateObj.platformUser;
            let orderData = that.orderData;
            orderData.cells[0].showCountNum = UserInfo.unpayedCount;
            orderData.cells[1].showCountNum = UserInfo.unsendedCount;
            orderData.cells[2].showCountNum = UserInfo.unreceivedCount; // 11111
            if(UserInfo.belongMendian){
                that.gainMenDianDetail(UserInfo.belongMendian);
                that.getTongji(UserInfo.belongMendian,'cur');
                that.getTongji(UserInfo.belongMendian,'per');
            }
            let loginUser = res.data.relateObj;
            let curPersonnelType = that.curPersonnelType;
            let moreSelectType = that.moreSelectType;
            let havaMoreSelectType = [];
            let havaMoreSelectTypeArr = [];
            console.log("===moreSelectType===", moreSelectType);

            for (let i = 0; i < moreSelectType.length; i++) {
              if (loginUser.platformUser.managerMendianId && moreSelectType[i].typeText == 'mendian') {
                havaMoreSelectType.push(moreSelectType[i]);
              }

              if (loginUser.platformUser.managerServantId && moreSelectType[i].typeText == 'servant') {
                havaMoreSelectType.push(moreSelectType[i]);
              }

              if (loginUser.platformUser.managerServantTargetId && moreSelectType[i].typeText == 'servantTarget') {
                havaMoreSelectType.push(moreSelectType[i]);
              }
            }

            console.log("moreSelectType", moreSelectType, havaMoreSelectType);

            if (havaMoreSelectType.length != 0) {
              for (let i = 0; i < havaMoreSelectType.length; i++) {
                havaMoreSelectTypeArr.push(havaMoreSelectType[i].text); // 判断优先度

                if (loginUser.platformUser.managerMendianId && loginUser.platformUser.managerMendianId != 0 && havaMoreSelectType[i].typeText == 'mendian') {
                  console.log("服务商");
                  curPersonnelType = i;
                } else if (!loginUser.platformUser.managerMendianId && loginUser.platformUser.managerServantId && loginUser.platformUser.managerServantId != 0 && havaMoreSelectType[i].typeText == 'servant') {
                  console.log("服务人员");
                  curPersonnelType = i;
                } else if (!loginUser.platformUser.managerMendianId && !loginUser.platformUser.managerServantId && loginUser.platformUser.managerServantTargetId && loginUser.platformUser.managerServantTargetId != 0 && havaMoreSelectType[i].typeText == 'servantTarget') {
                  console.log("服务对象");
                  curPersonnelType = i;
                }
              }
            }

            console.log("curPersonnelType", curPersonnelType, havaMoreSelectTypeArr);
            that.setData({
              curPersonnelType: curPersonnelType,
              loginUser: loginUser,
              userInfo: getApp().globalData.userInfo,
              setting: getApp().globalData.setting,
              orderData: orderData,
              havaMoreSelectTypeArr: havaMoreSelectTypeArr,
              havaMoreSelectType: havaMoreSelectType
            }); // 11111

            getApp().globalData.loginUser = res.data.relateObj;
            that.getMembersListData(loginUser)
          } else {
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
          }
        },
        fail: function (res) {
          console.log(res.data);
        },
        complete: function (res) {
          wx.stopPullDownRefresh();
        }
      });
    },
    //获取推广中心，查看是否有资格
    getTongji: function (mendianId,type) {
      console.log('-------推广中心--------');
      let that=this;
      let time=getApp().globalData.getNowTime('rail')+'-01';
      if(type=='per'){
         time=getApp().globalData.getNowTime('rail','per')+'-01';
      }
      console.log("===time===",time)
      let params={
          targetIds:mendianId,
          dateStr:time,
          pageSize:2,
          targetType:9,
      }
      var customIndex = getApp().globalData.AddClientUrl("/wx_find_target_month_tongji.html", params, 'get');
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===getTongji===", res);
          if (res.data.errcode == '0') {
              let mendianTongjiData=that.mendianTongjiData;
              if(type=='cur'){
                  mendianTongjiData.curData=res.data.relateObj.result[0]
              }else{
                  mendianTongjiData.perData=res.data.relateObj.result[0]
              }
              console.log("===mendianTongjiData==",mendianTongjiData)
              that.setData({mendianTongjiData:mendianTongjiData})
          }
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    // 默认门店获取数据
    gainMenDianDetail: function (mendianId) {
      console.log("======a=======")
      var that = this
      let menDian = {
        mendianId: mendianId,
      }
      let menDianYangShi = getApp().globalData.AddClientUrl("/mendian_detail.html", menDian, 'get')
      wx.request({
        url: menDianYangShi.url,
        data: menDianYangShi.params,
        header: getApp().globalData.headerPost,
        method: 'get',
        success: function (res) {
          console.log("======a=======", res)
          if (res.data.errcode == "-1") {
            wx.showToast({
              title: res.data.errMessage,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            })
          }
          else {
            // 直接拿到arr数据，放到wxml中去渲染
            that.setData({
              belongMendianDetail: res.data.relateObj,
            })
          }
        }
      })
    },
    getStateData: function (state) {
      let that = this;
      console.log("===getStateData===", state);
      that.selectComponent("#container").setPopupState(state);
    },
    bindGetUserInfo: function (e) {
      let that = this;
      that.setData({
        showPopup: false
      });
      console.log(that.showPopup);
      console.log(e.detail.userInfo);

      if (e.detail.userInfo) {
        //用户按了允许授权按钮
        console.log('用户按了允许授权按钮');
        //  && !getApp().globalData.loginUser.platformUser.nickname
        if (getApp().globalData.loginUser && getApp().globalData.loginUser.platformUser) {
          getApp().globalData.sentWxUserInfo(getApp().globalData.loginUser,function(loginUser){
              that.dellSData();
              that.getSessionUserInfo();
              that.getParac();
          });
        }
      } else {
        console.log('用户按了拒绝按钮'); //用户按了拒绝按钮
      }
    },
    cancel: function () {
      this.setData({
        showPopup: false
      });
    },
    loginSuccess: function (user) {
      console.log("pre apply mendian login success call back!", user);
      this.checkState();
    },
    loginFailed: function (err) {
      console.log("login failed!!");
    },
    checkState: function () {
      let that = this;
      console.log('======checkState.loginUser======', getApp().globalData.loginUser,getApp().globalData.setting);
      that.setData({
        loginUser: getApp().globalData.loginUser
      });
      that.dellSData();
      that.getSessionUserInfo();
      that.getParac();
      that.get_fx_detailFun()
    },
    /* 组件事件集合 */
    tolinkUrl: function (e) {
      let linkUrl = e.currentTarget ? e.currentTarget.dataset.link : e;
      getApp().globalData.linkEvent(linkUrl);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>